﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerController : MonoBehaviour
{
    public float speed = 10f;
    public float horizontalInput;
    public float xRange = 16f;
    public GameObject pizzaPrefab;
    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        horizontalInput = Input.GetAxisRaw("Horizontal");  // -1,0,1

        transform.Translate(Vector3.right * horizontalInput * speed * Time.deltaTime);

        // 玩家限制右移至屏幕边界
        if (transform.position.x > xRange) 
        {
            transform.position = new Vector3(xRange, 0, 0);
        }

        // 玩家限制左移至屏幕边界
        if (transform.position.x < -xRange)
        {
            transform.position = new Vector3(-xRange, 0, 0);
        }

        if(Input.GetKeyDown(KeyCode.Space))
        {
            // 发射披萨
            Instantiate(pizzaPrefab, transform.position, pizzaPrefab.transform.rotation);
        }
    }
}
